﻿using System.ComponentModel;

namespace AI3SaveEditor.AI3Files
{
    public abstract class ClothesFile : AI3File
    {
        const int NameLength = 64;

        public ClothesFile(string fileName) : base(fileName) { }

        [Category("服饰"), DisplayName("服饰名"), Description("服饰名")]
        public virtual string Name {
            get { return name; }
            set {
                this.name = value;
                IllusionUtils.SetString(value, buffer, 4, NameLength);
            }
        }

        private string name;

        public override void Load() {
            this.buffer = IllusionUtils.CMIDecrypt.DecryptFile(this.file.FullName);

            IllusionUtils.CMIDecrypt.DecryptString(this.buffer, 4, NameLength);
            this.name = IllusionUtils.GetStringWithTrimNull(this.buffer, 4, NameLength);
        }

        protected override void DecryptFileContent(byte[] fileContent) {
            IllusionUtils.CMIDecrypt.DecryptString(fileContent, 4, NameLength);
            IllusionUtils.CMIDecrypt.DecryptBuffer(fileContent);
        }

        public void ChangeFileNameToClothesName() {
            this.Save();
            ChangeFileName();
        }

        public abstract void ChangeFileName();
    }
}
